<?php
class Pages_IndexController extends Zend_Controller_Action {
	/**
	 * 
	 * Просмотр страницы
	 * @throws Zend_Controller_Action_Exception
	 */
	public function indexAction() {
		$slug = $this->_request->getParam('slug',null);
		
		$mapper = Doctrine_Core::getTable('Pages_Model_Page');
		$pages = $mapper->findOneByAlias($slug);
		
		if(!$pages || !$slug) 
			throw new Zend_Controller_Action_Exception('Page not found', 404);
			
		$title = $pages->Translation[$this->view->LANG]->name;
		$description = $pages->Translation[$this->view->LANG]->description;
		$keywords = $pages->Translation[$this->view->LANG]->keywords;
		
		$this->view->headMeta()->appendName('keywords', $keywords);
		$this->view->headMeta()->appendName('description', $description);
		$this->view->headTitle($title);
		
		$this->view->page = $pages;
	}
	
	public function contactsAction() {
		$contacts = Doctrine_Query::create()
					->from('Pages_Model_Contacts')
					->where('published = ?', true)
					->orderBy('id ASC')
					->execute();
		$this->view->contacts = $contacts;
		
		//устананавливаем метатеги для главной страницы
		$setting = Doctrine_Core::getTable('Default_Model_Settings')->find(1);
		if($setting) {
			$this->view->headMeta()->appendName('description', $setting->Translation[$this->view->LANG]->seo_description);
			$this->view->headMeta()->appendName('keywords', $setting->Translation[$this->view->LANG]->seo_keywords);
		}
		$this->view->headTitle($this->view->translate('CONTACTS'));
	}
}